package best.driver.android;

import android.content.SharedPreferences;
import best.driver.android.R;
import best.driver.android.common.app.IAppConfig;
import best.driver.android.manager.UserInfoManager;

public class AppConfig implements IAppConfig {

    public static final int DISTANCE_INTERVAL = 1;

    public static final int TIME_INTERVAL = 1;

    public static final String APP_VERSION = "1.0.2";

    public String mSocketHostUrl;
    private String mApiHostUrl;
    private String mSocketPort;
    public static enum ContextMode {
        TEST, PRE_ONLINE, ONLINE
    }

    public static ContextMode currentContextMode = ContextMode.ONLINE;
    public static String BASE_DATA_DIR = null;

    public static void loadContextMode(){

        int status = UserInfoManager.getInstance().getEnvironmentCode();
        if (status == ContextMode.TEST.ordinal()) {
            currentContextMode = ContextMode.TEST;
        } else if (status == ContextMode.ONLINE.ordinal()) {
            currentContextMode = ContextMode.ONLINE;
        } else if (status == ContextMode.PRE_ONLINE.ordinal()) {
            currentContextMode = ContextMode.PRE_ONLINE;
        }
    }


    @Override
    public String getApiHostUrl() {
        if(!BuildConfig.DEBUG) {
            mApiHostUrl = CustomerAppProxy.getProxy().getContext().getString(R.string.api_host_url_online);
        } else {
            switch (currentContextMode) {
                case TEST:
                    mApiHostUrl = CustomerAppProxy.getProxy().getContext().getString(R.string.api_host_url_ali_test);
                    break;
                case PRE_ONLINE:
                    mApiHostUrl = CustomerAppProxy.getProxy().getContext().getString(R.string.api_host_url_develop);
                    break;
                case ONLINE:
                    mApiHostUrl = CustomerAppProxy.getProxy().getContext().getString(R.string.api_host_url_online);
                    break;

            }
        }
        return mApiHostUrl;
    }

    @Override
    public String getSocketHostUrl() {
        if(!BuildConfig.DEBUG) {
            mSocketHostUrl = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_online);
        } else {
            switch (currentContextMode) {
                case TEST:
                    mSocketHostUrl = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_ali_test);
                    break;
                case PRE_ONLINE:
                    mSocketHostUrl = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_develop);
                    break;
                case ONLINE:
                    mSocketHostUrl = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_online);
                    break;

            }
        }
        return mSocketHostUrl;
    }

    @Override
    public int getSocketPort() {
        if(!BuildConfig.DEBUG) {
            mSocketPort = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_online_port);
        } else {
            switch (currentContextMode) {
                case TEST:
                    mSocketPort = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_ali_test_port);
                    break;
                case PRE_ONLINE:
                    mSocketPort = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_develop_port);
                    break;
                case ONLINE:
                    mSocketPort = BestApp.getInstance().getApplicationContext().getString(R.string.socket_host_url_online_port);
                    break;

            }
        }
        return Integer.valueOf(mSocketPort);
    }

    @Override
    public String getAppVersion() {
        return "";
    }

    @Override
    public String getAppKey() {
        //return BuildConfig.APP_KEY;
        return  "";
    }

    @Override
    public String getSecureKey() {
        //return BuildConfig.APP_SECURE_KEY;
        return  "";
    }



    @Override
    public int getHttpTimeout() {
        //return BuildConfig.HTTP_TIME_OUT;
        return  20;
    }





}
